package com.elisoft.emlap.zookeeper.web;

import com.elisoft.emlap.common.Result;
import com.elisoft.emlap.zookeeper.api.AppGoodsAPIService;
import com.elisoft.emlap.zookeeper.base.BaseController;
import com.elisoft.emlap.zookeeper.common.Constant;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 代理商销售记录商品信息Controller
 * @author wuyanshen
 * @version 2018-08-22
 */

@RestController
@RequestMapping(value = "goodsConsumer")
public class AgentAppGoodsController extends BaseController {

	@Autowired
    private AppGoodsAPIService appGoodsAPIService;

	@Autowired
    private Constant constant;


	@GetMapping("version")
    public String version() {
        logger.info("version 当前线程池名称：{}",Thread.currentThread().getName());
	    return constant.getVersion();
    }

//    @HystrixCommand(fallbackMethod = "goodsListFallBack")
    @GetMapping(value = "goodsList")
    public Result list() {
        logger.info("list 当前线程池名称：{}",Thread.currentThread().getName());
        Result result = appGoodsAPIService.list();
        logger.info("请求结果：message = {}", result.getMessage());

        //fastJson将字符串转换成list
//         String listTxt = JSONArray.toJSONString(result.getData());
//         List<AgentAppGoods> list = JSONObject.parseArray(listTxt, AgentAppGoods.class);

        return result;
    }

    //注解方式的 fallback方法
    public Result goodsListFallBack() {
        return Result.fail("调用接口超时，服务降级，返回友好提示");
    }


}